package com.lanou.web.controller;

import com.lanou.service.CartService;
import com.lanou.utils.ShiHuiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by QuChao on 2018/12/3
 */
@RestController
@RequestMapping("/member")
public class CartController {
    @Autowired
    private CartService cartService;

    @PostMapping("/cartList")
    public Map<String, Object> getCartList(@RequestBody Map<String, Object> map) {
        List<Map<String, Object>> cartList = cartService.getCartListByUid(map);
        return cartList.isEmpty() ? ShiHuiResult.error(400) : ShiHuiResult.ok(cartList);
    }

    @PostMapping("/cartEdit")
    public Map<String, Object> editCart(@RequestBody Map<String, Object> map) {
        Map<String, Object> map1 = cartService.editByUid(map);
        return map1.get("status").equals(400) ? ShiHuiResult.error(400) : ShiHuiResult.ok(map.get("data"));
    }

    @PostMapping("/cartDel")
    public Map<String, Object> delete(@RequestBody Map<String, Object> map) {
        return cartService.delete(map);
    }

    @PostMapping("/editCheckAll")
    public Map<String, Object> checkAll(@RequestBody Map<String, Object> map) {
        return cartService.checkAll(map);
    }
}
